import { getMenu } from "../api/base.js";

const state = {
  tabList: JSON.parse(localStorage.getItem("tabList")) || [],
  iscollapse: false,
  menuList:JSON.parse(localStorage.getItem('menuList')) ||[{path:'/Home',label:'系统首页'}],
};

const actions = {
  //获取菜单 需要token
  async getMenuList({ commit }) {
    let result = await getMenu();
    if (result.data.code == 200) {
      commit("GETMENULIST", result.data.data);
    } else {
      ElMessage.error(result.data.msg);
    }
  },
};

const mutations = {
  GETMENULIST(state, data) {
    localStorage.setItem("tabList", JSON.stringify(data));
    state.tabList = data;
  },
  ISCOLLAPSE(state) {
    state.iscollapse = !state.iscollapse;
  },
  PUSHMENU(state,menu){
    state.menuList=menu
    localStorage.setItem('menuList',JSON.stringify(menu))
  }
};

const getters = {};
export default {
  state,
  actions,
  mutations,
  getters,
};
